import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { ModelModule } from 'src/modules/model/model.module';
import { ChatModule } from '../chat/chat.module';
import { UserModule } from '../user/user.module';
import { TemplateModule } from '../template/template.module';
import { KitsModule } from '../kits/kits.module';
import { LabelsModule } from '../labels/labels.module';
import { DialogModule } from '../dialog/dialog.module';
import { FilesModule } from '../files/files.module';
import { TypeOrmModule } from '@nestjs/typeorm';
import * as path from 'path';
import { MockModule } from '../mock/mock.module';
import { ActionLogsModule } from '../action-logs/action-logs.module';
import { UserBehaviorModule } from '../user-behavior/user-behavior.module';
import { DifyKnowledgeApiModule } from '../dify-knowledge-api/dify-knowledge-api.module';

@Module({
  imports: [
    TypeOrmModule.forRootAsync({
      imports: [ConfigModule],
      inject: [ConfigService],
      useFactory: (configService: ConfigService) => ({
        type: 'mysql',
        host: configService.get('DB_HOST'),
        port: configService.get<number>('DB_PORT'),
        username: configService.get('DB_USERNAME'),
        password: configService.get('DB_PASSWORD'),
        database: configService.get('DB_DATABASE'),
        entities: [path.join(__dirname, '../') + '/**/*.entity{.ts,.js}'],
        synchronize: true,
      }),
    }),
    ConfigModule.forRoot({
      envFilePath: `.env.${process.env.NODE_ENV || 'development'}`,
    }),
    ModelModule,
    ChatModule,
    UserModule,
    TemplateModule,
    KitsModule,
    LabelsModule,
    DialogModule,
    FilesModule, //静态文件
    MockModule,
    ActionLogsModule,
    UserBehaviorModule,
    DifyKnowledgeApiModule,
  ],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule {}
